Logic for capturing unique characteristics in an object array. C# LINQ [closed]

Posted by Shawn H. on Programmers See other posts from Programmers or by Shawn H.
Published on 2012-10-26T13:23:29Z Indexed on 2012/10/26 17:19 UTC
Read the original article Hit count: 458

Filed under:
|

Given the following "response" or array of objects, what would be the most efficient way to get the desired results. There must be an easier way than the exhaustive and tedious way I'm doing it now. A LINQ solution would be fantastic.

Situation #1

<things>
  <thing id="1">
    <feature>Tall</feature>   
  </thing>
  <thing  id="2">
    <feature>Tall</feature>   
  </thing>
  <thing  id="3">
    <feature>Tall</feature>   
    <feature>Wide</feature>
  </thing>
  <thing  id="4">
    <feature>Tall</feature>   
  </thing>
</things>

Result: Wide


Situation #2

<things>
  <thing id="1">
    <feature>Short</feature>   
  </thing>
  <thing  id="2">
    <feature>Tall</feature>   
  </thing>
  <thing  id="3">
    <feature>Tall</feature>   
    <feature>Wide</feature>
  </thing>
  <thing  id="4">
    <feature>Tall</feature>   
  </thing>
</things>

Result: Wide, Short, Tall


Situation #3

<things>
  <thing id="1">
    <feature>Tall</feature> 
    <feature>Thin</feature>   
  </thing>
  <thing  id="2">
    <feature>Tall</feature>   
  </thing>
  <thing  id="3">
    <feature>Tall</feature>   
    <feature>Wide</feature>
  </thing>
  <thing  id="4">
    <feature>Tall</feature>   
  </thing>
</things>

Result: Wide, Thin


Thanks.

© Programmers or respective owner

Related posts about c#

Related posts about LINQ